package cn.itcast.user.web;

import cn.itcast.user.config.PatternProerties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@Slf4j
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {
	
	@Resource
	private UserService userService;
	@Value("${pattern.dateformate}")
	private String dateFormate;
	@Autowired
	private PatternProerties patternProerties;

	@GetMapping("/date")
	public String date() {
		LocalDateTime now = LocalDateTime.now();
		return 	now.format(DateTimeFormatter.ofPattern(dateFormate, Locale.CHINA));
	}
	@GetMapping("/env")
	public PatternProerties getPatternProerties(){
		return patternProerties;
	}
	
	/**
	 * 路径： /user/110
	 * @param id 用户id
	 * @return 用户
	 */
	@GetMapping("/{id}")
	public User queryById(@PathVariable("id") Long id,@RequestHeader(required=false) String name) {
		log.info("name:{}", name);
		return userService.queryById(id);
	}
}
